﻿//-----------------------------------------------------------------------
// <copyright file="ConfirmationPopup.cs" author="Artak Mkrtchyan">
//     Creative Commons - GNU General Public License (http://creativecommons.org/licenses/GPL/2.0/
// </copyright>
// <author>Artak Mkrtchyan</author>
// <email>mkArtak@gmail.com</email>
// <date>30/03/2013</date>
//-----------------------------------------------------------------------
using System;
using System.Windows;
using System.Windows.Media;

namespace ConsoleHoster.Common.View.Popups
{
	/// <summary>
	/// Interaction logic for ConfirmationPopup.xaml
	/// </summary>
	public partial class ConfirmationPopup : Window
	{
		public static MessageBoxResult Show(Window argOwner, string argTitle, string argQuestion, string argDetails, string argDetailsHeader, Func<ImageSource> argIconProvider = null, Style argWindowStyle = null)
		{
			ConfirmationPopup tmpPopup = new ConfirmationPopup(argTitle, argQuestion, argDetails, argDetailsHeader, argIconProvider);
			if (argOwner != null)
			{
				tmpPopup.Owner = argOwner;
			}

			if (argWindowStyle != null)
			{
				tmpPopup.Style = argWindowStyle;
			}
			tmpPopup.ShowDialog();

			MessageBoxResult tmpResult = (tmpPopup.DialogResult.HasValue && tmpPopup.DialogResult.Value) ? MessageBoxResult.Yes : MessageBoxResult.No;
			return tmpResult;
		}

		internal ConfirmationPopup(string argTitle, string argQuestion, string argDetails, string argDetailsHeader, Func<ImageSource> argIconProvider = null)
			: this()
		{
			this.Title = argTitle;
			this.txbQuestion.Text = argQuestion;
			this.txbDetails.Text = argDetails;

			if (argIconProvider != null)
			{
				this.Icon = argIconProvider();
			}

			this.expDetails.Header = argDetailsHeader;
			this.expDetails.Visibility = string.IsNullOrWhiteSpace(argDetails) ? Visibility.Collapsed : Visibility.Visible;
		}

		internal ConfirmationPopup()
		{
			InitializeComponent();
		}

		private void btnYes_Click(object sender, RoutedEventArgs e)
		{
			this.DialogResult = true;
		}

		private void btnNo_Click(object sender, RoutedEventArgs e)
		{
			this.DialogResult = false;
		}
	}
}
